<?php header("Content-Type:text/html;   charset=utf-8"); ?>
<script type="text/javascript">
	$(function(){		
		loadImgConfig();
		$("#btnSubmitImgConfig").bind("click",submitImgConfig);
		$("#imgUrlConfig").bind("click",function(){
			$("#fileImgConfig").trigger("click");
		});
		bindSubmitImgConfig();
		$("#fileImgConfig").bind("change",loadImgConfigImg);
		$("#btnDelImgConfig").bind("click",function(){
			saveImgConfig("");
			loadImgConfig();
		});
	});	
	function bindSubmitImgConfig(){	
		var options = {  
		        beforeSubmit:  showRequestImgConfig,  //提交前处理 
		        success:       showResponseImgConfig,  //处理完成 
		        resetForm: false,  
		        dataType:  'json'  
		    };  
		  
		    $('#formImgConfig').submit(function() {			    
		        $(this).ajaxSubmit(options);
		        return false;
		    });  
	}
	function showRequestImgConfig(formData, jqForm, options) {		
	    return true;  
	}  
	  
	function showResponseImgConfig(data, statusText)  {
	    if(data.ReturnCode==1){
		    $("#imgUrlConfig").attr("src",data.src);
			saveImgConfig(data.src);
	    }else{
	        
	    }
	    return false;   
	} 
	function saveImgConfig(src){
		var params = {imgurl:src};
		$.ajax({
			type:"post",
			url:"admin.php/manage/saveImgConfig",
			dataType:"json",
			data:params,
			async:false,
			success:function(data){
				
			}
		});
	}
	
	function submitImgConfig(){	
		if(checkImgConfig("txtImgTextConfig",25)==false)
			return false;
		
		var imgtext = $("#txtImgTextConfig").val();
		var capacity = $("#txtCapacityConfig").val();
		var location = $("#selLocationConfig").val();
		var limitsize = $("#txtLimitSizeConfig").val();
		var imgtype = $("#txtImgTypeConfig").val();
		var isvalid = $("#selIsvalidConfig").val();

		if(!IsDecimal(capacity) && !IsInt(capacity)){
			SetError("txtCapacityConfig","非有效数字");
			return false;
		}else if(parseFloat(capacity)<0 || parseFloat(capacity)>1){
			SetError("txtCapacityConfig","非有效数字");
			return false;
		}
		ClearError("txtCapacityConfig");
		if(!IsInt(limitsize)){
			SetError("txtLimitSizeConfig","非有效数字");
			return;
		}
		if(parseInt(limitsize)<0 || parseInt(limitsize)>100){
			SetError("txtLimitSizeConfig","0-100M之间");
			return;
		}
		ClearError("txtLimitSizeConfig");
		
		if(checkImgConfig("txtImgTypeConfig",100)==false)
			return false;
		
		
		
		var params = {
					imgtext:imgtext,
					capacity:capacity,
					location:location,
					limitsize:limitsize,
					imgtype:imgtype,
					isvalid:isvalid
				};
		//alert(params.imgtext+"--"+params.capacity+"-"+params.location+"-"+params.limitsize+"-"+params.isvalid);
		
		$.ajax({
			type:"post",
			url:"admin.php/manage/setImgConfig",
			dataType:"json",
			data:params,
			success:function(data){
				loadImgConfig();
				alert("提交成功");
			}
		});
	}
	
	function loadImgConfig(){		
		$.ajax({
			type:"post",
			url:"admin.php/manage/getImgConfig",
			dataType:"json",			
			success:function(data){
				$("#txtImgTextConfig").val(data.imgtext);
				$("#txtCapacityConfig").val(data.capacity);
				$("#selLocationConfig").val(data.location);
				$("#txtLimitSizeConfig").val(data.limitsize);
				$("#txtImgTypeConfig").val(data.imgtype);
				$("#selIsvalidConfig").val(data.isvalid);
				$("#imgUrlConfig").attr("src",data.imgurl);
			}
		});
	}

	function loadImgConfigImg(){
		var fileName = $("#fileImgConfig").val();
		var ext=fileName.substr(fileName.indexOf(".")).toLowerCase();
		if(ext!=".gif" && ext!=".jpg" && ext!=".jpeg" && ext!=".png" && ext!=""){
			alert("图片格式无效");		
			return;
		}
		if(!IsEmpty(fileName)){	
			$("#formImgConfig").submit();
			return false;
		}	
	}
	function checkImgConfig(id,len){
		var name = $("#"+id).val();
		var length = name.length;
		if(length>len){
			SetError(id,"最多"+len+"个字符");
			return false;
		}
		ClearError(id);
		return true;
	}
	
</script>
<div class="pageContent">
	<form id="formImgConfig" class="pageForm required-validate"
		action="admin.php/manage/uploadImg/mypicimgconfig" method="post"
		enctype="multipart/form-data">
		<div class="pageFormContent" style="width: 98%;" layoutH="56">
			<input type='file' id='fileImgConfig' name='mypicimgconfig' style='display: none'>

			<table class="tableNewUser">
				<tr>
					<td>水印图片：</td>
					<td
						style="vertical-align: middle; line-height: 130px; clear: both; width: 260px;"><input
						type="text" id="txtImgTextConfig" style="clear: both"></td>
					<td style="text-align: left"><img id="imgUrlConfig"
						style="width: 60px; height: 60px; vertical-align: middle; cursor: pointer">

						<input type="button" id="btnDelImgConfig" value="删除"
						style="width: 80px"></td>
				</tr>

				<tr>
					<td>水印透明度(0-1之间)：</td>
					<td colspan="2"><input type="text" id="txtCapacityConfig"></td>
				</tr>
				<tr>
					<td>水印位置：</td>
					<td colspan="2"><select id="selLocationConfig" style="width: 245px">
							<option value="1">左上</option>
							<option value="2">右上</option>
							<option value="3">中间</option>
							<option value="4">左下</option>
							<option value="5">右下</option>
					</select></td>
				</tr>
				<tr>
					<td>图片字节限制(M)：</td>
					<td colspan="2"><input type="text" id="txtLimitSizeConfig"></td>
				</tr>
				<tr>
					<td>图片类型：</td>
					<td colspan="2"><input type="text" id="txtImgTypeConfig"></td>
				</tr>
				<tr>
					<td>水印开启：</td>
					<td colspan="2"><select id="selIsvalidConfig" style="width: 245px">
							<option value="1">开启</option>
							<option value="0">关闭</option>
					</select></td>
				</tr>

				<tr>
					<td colspan="3" style='line-height: 40px'>&nbsp;&nbsp;</td>
				</tr>
			</table>
		

			<div class="buttonActive" style="width: 120px; margin-left: 50px;">
				<div class="buttonContent">
					<button id="btnSubmitImgConfig" type="button" style="width: 80px">提 交</button>
				</div>
			</div>

			<div class="button" style="text-align: right">
				<div class="buttonContent" style="text-align: right">
					<button id="btnCloseImgConfig" type="button" class="close"
						style="width: 80px">关 闭</button>
				</div>
			</div>
		</div>
	</form>
</div>
